package cn.dansj.handler;

import cn.dansj.common.jdbc.DBUtils;
import cn.dansj.service.InterfaceInfoService;
import cn.dansj.common.context.ApplicationContextProvider;
import cn.dansj.common.context.GetEnvironment;
import cn.dansj.common.redis.RedisUtils;
import org.springframework.jdbc.core.JdbcTemplate;

public abstract class InterfaceHandler implements Interface {
    protected static final JdbcTemplate jdbcTemplate;
    protected static final RedisUtils redisUtils;
    protected static final InterfaceInfoService interfaceInfoService;
    protected static final String dbType;
    private long version = -1;

    public void setVersion(long version) {
        if (this.version == -1) {
            this.version = version;
        } else {
            throw new IllegalArgumentException(this.version + "版本信息不可以重置");
        }
    }

    public long getVersion() {
        return version;
    }

    //静态变量初始化一次
    static {
        jdbcTemplate = ApplicationContextProvider.getBean(JdbcTemplate.class);
        redisUtils = ApplicationContextProvider.getBean(RedisUtils.class);
        interfaceInfoService = ApplicationContextProvider.getBean(InterfaceInfoService.class);
        dbType = DBUtils.getDbType(GetEnvironment.get("spring.datasource.druid.url"));
    }
}
